﻿/**************************************************************************
创建日期:	2019/6/10  
作	  者:	张存
邮 	  箱:	zhangcunliang@126.com
创建时间:	
Copyright (c)  ZhCun.cn

描	述：
记	录：
***************************************************************************/
using ASmile.Helpers;
using System;
using System.Collections.Generic;
using System.Text;

namespace ASmile
{
    public class AppConfigBase<T> where T : class, new()
    {
        static T _Config;

        internal static void LoadConfigItem()
        {
            if (_Config == null) _Config = new T();
            string[] configKeys = ReflectionHelper.GetPropertyNames(_Config.GetType());
            Dictionary<string, object> configItems = new Dictionary<string, object>();
            foreach (var key in configKeys)
            {
                string v = ConfigHelper.GetAppSettings(key);
                configItems.Add(key, v);
            }

            ReflectionHelper.SetPropertyValue(_Config, configItems);
        }

        public static T AppSettings
        {
            get
            {
                if (_Config == null || ConfigHelper.ConfigFileChanged)
                {
                    ConfigHelper.ConfigFileChanged = false;
                    LoadConfigItem();
                }
                return _Config;
            }
        }
    }
}